﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpenseSystem.Common;
using ExpenseSystem.Common.BaseModel;
using ExpenseSystem.DataUpdater;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Core.DataAddOn;
using System.Web;

namespace ExpenseSystem.Core.ServiceOrderModules
{
    public abstract class ServiceOrderManager:INormalManager<ServiceOrderModel>,IApproveable<ServiceOrderModel>
    {
        protected string tran = HttpContext.Current.Items[Definition.SESSION_TRAN_STR].ToString();

        protected ServiceOrderManager()
        {
            profile = Authority.Authority.GetUserProfile();
        }

        protected UserProfile profile;
        public static ServiceOrderManager CreateInstance()
        {
            return new ServiceOrderStateUpdateManager( new ServiceOrderBaseManager());
        }
        protected NormalDataUpdater<ServiceOrderModel> ServiceOrderUpdater = new ServiceOrderUpdaterRegister().GetServiceOrderUpdater();

        public abstract bool Delete( ServiceOrderModel ServiceOrder, out string message);
        public abstract bool DeleteById( long[] ServiceOrderId,  out string message);
        public abstract bool Save(ServiceOrderModel ServiceOrder, out string message,params IAddable<ServiceOrderModel>[] addables);

        public virtual bool Approved(long id, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Approved(id, out message);
        }

        public virtual bool Reject(long id, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Reject(id, out message);
        }

        public virtual bool Comfirm(long id, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Comfirm(id, out message);
        }

        public virtual bool Submit(long modelid, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Submit(modelid, out message);
        }

        public virtual bool Recall(long modelid, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Recall(modelid, out message);
        }

        public virtual bool Revert(long modelid, out string message)
        {
            ApprovedHelper<ServiceOrderModel> approvedHelper = new ApprovedHelper<ServiceOrderModel>(new ServiceOrderFetcher(), this);
            return approvedHelper.Revert(modelid, out message);
        }
    }
}
